/**
 * 处理存在的sku路径
 */
import {
    combination
} from "./../../utils/util.js"

class SkuCode {
    code
    spuId
    codePathArr = [] // 当前sku所有路径组合
    constructor(code) {
        this.code = code

        this._splitCode()
    }

    _splitCode() {
        // code: "2$1-42#3-10#4-15"
        const spuAndSpec = this.code.split('$')
        this.spuId = spuAndSpec[0]
        const specCodeArr = spuAndSpec[1].split('#')

        let length = specCodeArr.length

        for (let i = 1; i <= length; i++) {
            const arr = combination(specCodeArr, i)
            const newArr = arr.map(item => {
                return item.join('#')
            })
            // 将一个sku所有可能的路径字典连接起来
            this.codePathArr = this.codePathArr.concat(newArr)
        }
    }

}
export {
    SkuCode
}